package com.example.reflect.springannotation.config;

import com.example.reflect.springannotation.enums.StrategyEnum;
import com.google.common.base.Throwables;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class CommonStrategy {

    @Autowired
    private CommonStrategy commonStrategy;

    /**
     * 执行目标计划
     * @return
     */
    public Object executeScheduler(StrategyEnum strategyEnum, String s, String o){
        try {
            return CommonScheduler.builder()
                    .modelClassPath(strategyEnum.getModelClassPath())
                    .scheduleClassPath(strategyEnum.getStrategyClassPath())
                    .build()
                    .dispatch(s,o);
        }catch (Exception e){
            log.error("执行计划失败_失败原因:{}", Throwables.getStackTraceAsString(e));
            throw new RuntimeException("执行计划失败！");
        }

    }
}
